<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>综合服务 试卷添加</title>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <!--JQ-->
    <script type="text/javascript" charset="utf-8"
            src="${re.contextPath}/plugin/common/js/jquery-1.8.3.min.js"></script>
    <!--Layui-->
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/common/js/comment.js" charset="utf-8"></script>
    <style>
        .layui-laypage-limits>select{
            width: 100% !important;
        }

        .layui-laypage .layui-laypage-curr .layui-laypage-em {
            background-color: #1E9FFF;
        }
    </style>
</head>

<body>
<!--容器-->

<div class="container index clearfix">
    <!--右侧内容-->
    <div class="Right fr" style="width: 100%;">
        <div  lay-filter="docDemoTabBrief" style="margin-top: 12px;">
            <div style="background-color: #F1F4FB;border-radius: 5px;padding:14px 10px;">
                <div class="layui-row">
                    <div class="layui-col-md4" style="padding-left:1%">
                        <input type="hidden" id="examId" name="examId" value="${examId}">
                        <input id="paperName" class="layui-input layui-input-inline" name="paperName" type="text" placeholder="请输入试卷名称" style="width: 50%">
                        <#--				<input class="layui-btn layui-btn-danger layui-btn-sm fr ml10" type="button" value="重置" onclick="resetQuery()">-->
                        <input class="layui-btn layui-btn-normal" type="button" value="筛选" onclick="query()">
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<div class="layui-container"
     style="background-color: #ffffff;width:96%;margin-top:30px;padding:16px;border-radius: 10px">
    <div class="layui-row" style="width: 100%;text-align: center">
        <table id="tableList" class="layui-hide" lay-filter="tableList"></table>
        <button type="button" class="layui-btn layui-btn-normal white ft18 close" onclick="closes()">取消</button>
        <button type="button" lay-submit class="layui-btn layui-btn-normal bluebg white ft18 " onclick="add()">保存</button>
    </div>

</div>
<script type="text/javascript" src="${re.contextPath}/pageoffice.js" id="po_js_main"></script>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script>
    var layer;
    var tableIns;
    $(function () {
        layui.use(['table'], function () {
            table = layui.table;
            //方法级渲染
            tableIns = table.render({
                id: 'tableList',
                elem: '#tableList',
                url: '/exam/list/selectExPaper?examId='+$("#examId").val(),
                page: true,
                cols: [[
                    {type:'checkbox'},
                    {
                        title: '序号', width: '10%', templet: function (res) {
                            return res.LAY_INDEX;
                        }
                    },
                    {field: 'paperId', title: 'ID', hide: true, sort: false},
                    {field: 'paperName', title: '试卷名称', width: '26.5%', sort: false},
                    {field: 'paperType', title: '试卷类型', width: '15%', sort: false},
                    {field: 'paperSort', title: '试卷类别', width: '10%', sort: false},
                    {field: 'totalScore', title: '试卷总分', width: '10%', sort: false},
                    {field: 'totalNum', title: '试题总数', width: '10%', sort: false},
                    {field: 'createDate', title: '创建时间', width: '15%', sort: false},
                ]],
            });
        })
    })

    //筛选
    function query() {
        var paperName = $('#paperName').val();
        jsondata = {
            paperName: paperName
        };
        table.reload('tableList', {where: jsondata});
    }
    //取消
    function closes(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    //添加(只能选择总分一样的试卷)
    function add(){
        var data = table.checkStatus('tableList').data;
        var ids=[];
        for(var i=0;i<data.length;i++){
            ids.push(data[i].paperId);
            if(data[0].totalScore!=data[i].totalScore){
                layer.msg("请选择总分一样的试卷!",{icon:2});
                return false;
            }

        }
        if (data.length <= 0){
            layer.msg("请选择试卷",{icon: 2});
            return false;
        }
        var json={
            ids:ids,
            examId:$("#examId").val()
        }
        layerAjaxGet("/exam/list/insertExExamPaper",json,"",function (d) {
            if(d.flag){
               layer.msg("操作成功!",{icon:2});
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }else {
                layer.msg("操作失败!",{icon:2});
            }
        })
    }

</script>
</body>
</html>